package com.zhaosc.elasticsearch;

import java.io.IOException;

import org.apache.log4j.Logger;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.unit.TimeValue;
import org.junit.Test;

/**
 * https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.5/java-rest-high-document-delete.html
 * 
 * @author zhaosc
 *
 */
public class DeletTest extends BaseTest {

	private static final Logger logger = Logger.getLogger(DeletTest.class);

	@Test
	public void testDelete01() {
		DeleteRequest deleteRequest = new DeleteRequest(index, "1");

		deleteRequest.timeout(TimeValue.timeValueMinutes(2));
		deleteRequest.timeout("2m");
		deleteRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);

		try {
			DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT);
			
			if(DocWriteResponse.Result.DELETED==deleteResponse.getResult()) {
				logger.info("***success***");
			}else{
				logger.info("***fail***");
			}
			
		} catch (IOException e) {
			logger.error(e);
		}
	}

}
